Skip to main content

xsltApplyStylesheetFromFile

Type

function

Summary

Returns the data set resulting from applying the xslt document in the specified file against the specified xml document.

Syntax

xsltApplyStylesheetFromFile (<xmlDocID>,<pathToXSLTFile>)

Description

The xsltApplyStylesheetFromFile function returns the data set resulting from applying the xslt document in the specified file against the specified xml document. For instance, given xml data of

    &lt;sales&gt;

<division id="North">

        &lt;revenue&gt;10&lt;/revenue&gt;
&lt;growth&gt;9&lt;/growth&gt;
&lt;bonus&gt;7&lt;/bonus&gt;

</division>

        &lt;division id=\"South\"&gt;

<revenue>4</revenue>

        &lt;growth&gt;3&lt;/growth&gt;
&lt;bonus&gt;4&lt;/bonus&gt;

</division>

        &lt;division id=\"West\"&gt;

<revenue>6</revenue>

        &lt;growth&gt;-1.5&lt;/growth&gt;
&lt;bonus&gt;2&lt;/bonus&gt;

</division>

    &lt;/sales&gt;

and a file containing xslt data of

    &lt;html xsl:version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" lang=\"en\"&gt;
&lt;head&gt;

<title>Sales Results By Division</title>

        &lt;/head&gt;
&lt;body&gt;

<table border="1">

        &lt;tr&gt;

<th>Division</th>

        &lt;th&gt;Revenue&lt;/th&gt;
&lt;th&gt;Growth&lt;/th&gt;
&lt;th&gt;Bonus&lt;/th&gt;

</tr>

        &lt;xsl:for-each select=\"sales/division\"&gt;

<!-- order the result by revenue -->

        &lt;xsl:sort select=\"revenue\"
data-type=\"number\"
order=\"descending\"/&gt;

<tr>

        &lt;td&gt;

<em><xsl:value-of select="@id"/></em>

        &lt;/td&gt;
&lt;td&gt;

<xsl:value-of select="revenue"/>

        &lt;/td&gt;
&lt;td&gt;

<!-- highlight negative growth in red -->

        &lt;xsl:if test=\"growth &lt; 0\"&gt;

<xsl:attribute name="style">

        &lt;xsl:text&gt;color:red&lt;/xsl:text&gt;

</xsl:attribute>

        &lt;/xsl:if&gt;
&lt;xsl:value-of select=\"growth\"/&gt;

</td>

        &lt;td&gt;

<xsl:value-of select="bonus"/>

        &lt;/td&gt;

</tr>

        &lt;/xsl:for-each&gt;

</table>

        &lt;/body&gt;

</html>

You would end up with

    &lt;html lang=\"en\"&gt;
&lt;head&gt;
&lt;meta http-equiv=\"Content-Type\" content=\"text/html;
charset=UTF-8\"&gt; &lt;title&gt;Sales Results By Division&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;&lt;table border=\"1\"&gt;
&lt;tr&gt;
&lt;th&gt;Division&lt;/th&gt;
&lt;th&gt;Revenue&lt;/th&gt;
&lt;th&gt;Growth&lt;/th&gt;
&lt;th&gt;Bonus&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;North&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;West&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td style=\"color:red\"&gt;-1.5&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;South&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/body&gt;
&lt;/html&gt;

Parameters

NameTypeDescription

xmlDocID

string

The ID of the xml document to use.

pathToXSLTFile

string

The file path to the xslt document that will be applied to the xml document.

Examples

put xsltApplyStylesheetFromFile(tDocID, "getData.xml" ) into tProcessedData
put xsltApplyStylesheetFromFile(tDocID, tFilePath) into tProcessedData

function: revXMLEvaluateXpath, xsltLoadStylesheet, xsltLoadStylesheetFromFile, revXMLCreateTreeFromFile, revXMLCreateTree, xsltApplyStylesheetFromFile

Compatibility and Support

Introduced

LiveCode 6.5

OS

mac

windows

linux

ios

android

Platforms

desktop

server

mobile

Thank you for your feedback!

Was this page helpful?